home *** CD-ROM | disk | FTP | other *** search
/ Mission 3 / Mission 3.zip / Mission 3.iso / texte / 7up_pd / falert3d.c < prev    next >
C/C++ Source or Header  |  1998-10-29  |  7KB  |  213 lines

  1. /* Wohldesignte Alertbox. Nicht so ein TOS-Schund. */
  2. /*****************************************************************************
  3. *
  4. *                                   7UP
  5. *                              Modul: FALERT.C
  6. *                        (c) by Geiß & TheoSoft '92
  7. *
  8. *****************************************************************************/
  9. #define RSRC_CREATE
  10. #include <portab.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <aes.h>
  15. #include <tos.h>
  16.  
  17. static OBJECT *alert_tree;
  18.  
  19. #include "falert3d.h"
  20. #include "falert3d.rh"
  21. #include "falert3d.rsh"
  22.  
  23. /****** DEFINES **************************************************************/
  24.  
  25. #define MAX_HEIGHT    10
  26. #define NUM_SEP       5                 /* Anzahl Separatoren */
  27. #define SEP_OPEN      '['               /* Zeichen für Separator offen */
  28. #define SEP_CLOSE     ']'               /* Zeichen für Separator geschlossen */
  29. #define SEP_LINE      '|'               /* Zeichen für Zeilentrenner */
  30. #define MINBUT        7                 /* Mindestens 6 Buchstaben für Buttons */
  31. #define FLAGS15 0x8000
  32. /*****************************************************************************/
  33.  
  34. int form_exhndl(OBJECT *tree, int start, int mode);
  35. int form_fix(OBJECT *tree, int mode);
  36.  
  37. static void fix_tree(int n_tree)
  38. {
  39.   register int tree,     /* index for trees */
  40.                object;   /* index for objects */
  41.   OBJECT       *pobject;
  42.  
  43.   for (tree = 0; tree < n_tree; tree++) /* fix trees */
  44.   {
  45.     object  = 0;
  46.     pobject = rs_trindex [tree];
  47.     do
  48.     {
  49.       rsrc_obfix(pobject,object);
  50.     }
  51.     while (! (pobject [object++].ob_flags & LASTOB));
  52.   } /* for */
  53. } /* fix_tree */
  54.  
  55. #undef RSRC_CREATE
  56. /*****************************************************************************/
  57.  
  58. GLOBAL WORD form_alert (int def, const char *alertmsg)
  59. {
  60.     static int first=TRUE;
  61.  
  62.     WORD    ret, i, x, w, w1, w2, xdiff;
  63.     WORD    image, bell=FALSE, gl_wbox, gl_hbox;
  64.     WORD    maxstr, num_str, maxbut, num_buttons, lenbut;
  65.     BYTE    *p, *s;
  66.     char    str[51];
  67.     
  68.     graf_handle(&gl_wbox,&gl_hbox,&ret,&ret);
  69.     
  70.     if(first)
  71.     {
  72.         fix_tree(NUM_TREE);
  73.         alert_tree =(OBJECT *)rs_trindex[ROOT];
  74.         form_fix(alert_tree,TRUE);
  75.         first=FALSE;
  76.     }
  77.     alert_tree->ob_x=alert_tree->ob_y=0;
  78.  
  79.     w       = alert_tree [ASTRING0].ob_width / gl_wbox;
  80.     
  81.     p = strchr (alertmsg, SEP_OPEN) + 1;
  82.     sscanf (p, "%d", &image);                             /* Image einlesen */
  83.     if(image == 3) bell=TRUE;
  84.  
  85.    for(i=IMAGE0M; i<=IMAGE3D; i++)
  86.         alert_tree[i].ob_flags|=HIDETREE;
  87.    
  88.     alert_tree[IMAGE0D+2*image].ob_flags&=~HIDETREE;
  89.     alert_tree[IMAGE0M+2*image].ob_flags&=~HIDETREE;
  90.  
  91.     if(mindestens_16_Farben()) /* Hintergrundfarben setzen */
  92.     {
  93.         if(image == 0 || image == 3)
  94.            alert_tree[IMAGE0M+2*image].ob_spec.bitblk->bi_color=WHITE;
  95.         if(image == 1 || image == 2)
  96.            alert_tree[IMAGE0M+2*image].ob_spec.bitblk->bi_color=BLACK;
  97.    }
  98.    else
  99.        alert_tree[IMAGE0M+2*image].ob_spec.bitblk->bi_color=WHITE;
  100.    
  101.     alert_tree[IMAGE0M+2*image].ob_y=alert_tree[IMAGE0M].ob_y; /* positionieren */
  102.     alert_tree[IMAGE0D+2*image].ob_y=alert_tree[IMAGE0D].ob_y; /* positionieren */
  103.     
  104.     maxstr = 0;
  105.     p      = strchr (p, SEP_OPEN) + 1;
  106.     i      = ASTRING0;
  107.     num_str= 0;
  108.  
  109.     while (*p != SEP_CLOSE)                       /* Strings verarbeiten */
  110.     {
  111.         s = str;
  112.  
  113.         alert_tree[i].ob_flags&=~HIDETREE;
  114.  
  115.         while (((*p != SEP_CLOSE) || (p [1] != SEP_OPEN)) && (*p != SEP_LINE)) *s++ = *p++;
  116.         
  117.         *s      = EOS;
  118.         str [w] = EOS;
  119.         strcpy ((BYTE *)alert_tree [i].ob_spec.index, str);
  120.         maxstr = max (maxstr, strlen (str));
  121.         i++;
  122.         num_str++;
  123.         if (*p != SEP_CLOSE) p++;
  124.     } /* while */
  125.  
  126.     maxstr+=2; /* zwei Zeichen dazu, wg. Rand rechts */
  127.     
  128.     while (alert_tree [i].ob_type == G_STRING) 
  129.         alert_tree[i++].ob_flags|=HIDETREE;
  130.  
  131.     p = strchr (p, SEP_OPEN) + 1;
  132.     i = BUTTON0;
  133.     
  134.     do                                            /* Buttons verstecken */
  135.     {
  136.         alert_tree[i].ob_flags|=(HIDETREE|EXIT);
  137.         alert_tree[i].ob_flags&=~DEFAULT;
  138.         alert_tree[i].ob_state&=~DISABLED;
  139.     } while (! (alert_tree[i++].ob_flags & LASTOB));
  140.  
  141.     maxbut      = 0;
  142.     i           = BUTTON0;
  143.     num_buttons = 0;
  144.  
  145.     while (*p != SEP_CLOSE)                       /* Buttons verarbeiten */
  146.     {
  147.         s = (char *)((TEDINFO *)alert_tree[i].ob_spec.userblk->ub_parm)->te_ptext;
  148.  
  149.         alert_tree[i].ob_flags&=~HIDETREE;
  150.  
  151.         while ((*p != SEP_CLOSE) && (*p != SEP_LINE)) *s++ = *p++;
  152.         
  153.         *s     = EOS;
  154.         
  155.         lenbut=
  156.             (int)((TEDINFO *)alert_tree[i].ob_spec.userblk->ub_parm)->te_txtlen=
  157.             strlen((char *)((TEDINFO *)alert_tree[i].ob_spec.userblk->ub_parm)->te_ptext);
  158.         
  159.         if(strchr((char *)((TEDINFO *)alert_tree[i].ob_spec.userblk->ub_parm)->te_ptext,'_'))
  160.             lenbut--;
  161.         maxbut = max (maxbut, lenbut);
  162.         i++;
  163.         num_buttons++;
  164.         if (*p != SEP_CLOSE) p++;
  165.     } /* while */
  166.  
  167.     if (def != 0)
  168.     {
  169.         def += BUTTON0 - 1;
  170.         alert_tree[def].ob_flags|=DEFAULT;
  171.     } /* if */
  172.     
  173.     maxbut = max (maxbut, MINBUT);               /* Minimale Breite der Knöpfe */
  174.  
  175.     for (i = BUTTON0, x = 2*gl_wbox, maxbut += 2; i - BUTTON0 < num_buttons; i++)
  176.     {
  177.         alert_tree [i].ob_x     = x;
  178.         alert_tree [i].ob_width = maxbut * gl_wbox;
  179.         x += (maxbut + 1) * gl_wbox;
  180.     } /* for */
  181.     
  182.     alert_tree->ob_height= MAX_HEIGHT*gl_hbox - (NUM_SEP-max(3,num_str))*gl_hbox;
  183.     w1                   = alert_tree [ASTRING0].ob_x + maxstr * gl_wbox;
  184.     w2                   = alert_tree [BUTTON0 + num_buttons - 1].ob_x + maxbut * gl_wbox + gl_wbox;
  185.     alert_tree->ob_width = gl_wbox + max (w1, w2);
  186.     alert_tree[ROOT+1].ob_x=alert_tree->ob_width-gl_hbox-3; /* Eselsohr */
  187.     
  188.     if(gl_hbox<=8)
  189.     alert_tree[ROOT+1].ob_x-=gl_hbox;
  190.     
  191.     for (i = BUTTON0; i - BUTTON0 < num_buttons; i++)
  192.         alert_tree [i].ob_y  = alert_tree->ob_height - (2*gl_hbox+4) - 1;
  193.     
  194.     if (w1 > w2)             /* Buttons zentrieren */
  195.     for (i = BUTTON0; i - BUTTON0 < num_buttons; i++)
  196.         alert_tree [i].ob_x += (w1 - w2) / 2;
  197.  
  198.     i=BUTTON0+num_buttons-1; /* Buttons rechtsbündig... */
  199.     xdiff= alert_tree->ob_width -
  200.         (alert_tree[i].ob_x + alert_tree[i].ob_width) - (3*gl_wbox-4);
  201.     if(xdiff>0) 
  202.         for (i = BUTTON0; i - BUTTON0 < num_buttons; i++)
  203.             alert_tree [i].ob_x += xdiff;
  204.  
  205.     form_center (alert_tree, &ret, &ret, &ret, &ret);
  206.     
  207.     alert_tree->ob_flags|=FLAGS15; /* kein Windial!!!, weil kein Handle mehr frei*/
  208.       
  209.     if(bell) Bconout(2,7);
  210.     graf_mouse(ARROW,NULL);
  211.     return((form_exhndl(alert_tree,0,0)&0x7FFF)-BUTTON0+1);
  212. } /* open_alert */
  213.